package com.yunweiweishi.xuhuanpaltform.yuhuan_app.controller;


import com.yunweiweishi.xuhuanpaltform.yuhuan_app.comm.conf.CommonResult;
import com.yunweiweishi.xuhuanpaltform.yuhuan_app.pojo.EquipmentItem;
import com.yunweiweishi.xuhuanpaltform.yuhuan_app.pojo.EquipmentType;
import com.yunweiweishi.xuhuanpaltform.yuhuan_app.service.EquipmentItemService;
import com.yunweiweishi.xuhuanpaltform.yuhuan_app.service.EquipmentTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(value = "设备类型", tags = {"设备类型controller"})
@RestController
@RequestMapping("/EquipmentType")
public class EquipmentTypeController {



    @Autowired
    private EquipmentTypeService equipmentTypeService;


    @Autowired
    private CommonResult result;



    @Autowired
    private EquipmentItemService equipmentItemService;

    /**
     * 根据设备类型的名称 查询设备类型
     */

    @ApiOperation(value = "通过设备类型的名称查找设备")
    @GetMapping("/findByEquipmentTypeName")
    public CommonResult findByEquipmentTypeName(@RequestParam("equipmentTypeName") String equipmentTypeName) {


        try {
            EquipmentType equipmentType = equipmentTypeService.findByEquipmentTypeName(equipmentTypeName);
            result.setData(equipmentType);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            result.setState(500);
            result.setMsg("失败");
            return result;
        }
    }


    /**
     *
     * 添加设备类型
     */
    @ApiOperation(value = "添加设备类型")
    @PostMapping("/addEquipmentType")
    public CommonResult addEquipmentType(@RequestBody EquipmentType equipmentType) {

        try {

            equipmentTypeService.addEquipmentType(equipmentType);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            result.setState(500);
            result.setMsg("失败");
            return result;
        }

    }


    /**
     *
     * 更新设备类型
     */
    @ApiOperation(value = "更新设备类型")
    @PutMapping("/updateEquipmentType")
    public CommonResult updateEquipmentType(@RequestBody EquipmentType equipmentType) {

        try {

            equipmentTypeService.updateEquipmentType(equipmentType);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            result.setState(500);
            result.setMsg("失败");
            return result;
        }

    }

    @ApiOperation(value = "根据ID删除设备类型")
    @DeleteMapping("/EquipmentType/{id}")
    public void deleteEquipmentTypeById(@PathVariable("id") Long id) {

        equipmentTypeService.deleteEquipmentTypeById(id);

    }






    //*******************************以下是设备的巡检项


    @ApiOperation( value = "新增设备项")
    @PostMapping("/addEquipmentItem")
    public CommonResult addEquipmentItem(@RequestBody EquipmentItem equipmentItem) {

        try {

            equipmentItemService.addEquipmentItem(equipmentItem);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            result.setState(500);
            result.setMsg("失败");
            return result;
        }

    }

    @ApiOperation( value = "更新设备项")
    @PutMapping("/updateEquipmentItem")
    public CommonResult updateEquipmentItem(@RequestBody EquipmentItem equipmentItem) {

        try {

            equipmentItemService.updateEquipmentItem(equipmentItem);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            result.setState(500);
            result.setMsg("失败");
            return result;
        }

    }


    @ApiOperation( value = "根据id删除设备项")
    @DeleteMapping("/deleteEquipmentItem/{id}")
    public void deleteEquipmentItemById(@PathVariable("id") Long id) {

        equipmentItemService.deleteEquipmentItemById(id);

    }
}
